package HLCode.ASM;

import HLCode.HLCustomFunction;

public class HLASM_Jump implements HLIASM {
    int jumpTo;

    public int Load(byte[] data, int pos) {
        jumpTo = (data[pos] & 0xff) | ((data[pos + 1] << 8) & 0xff00);
        return pos + 2;
    }

    public void Adjust(int[] lineIndexList) {
        for (int i = lineIndexList.length - 1; i >= 0; i--) {
            if (jumpTo == lineIndexList[i]) {
                jumpTo = i;
                return;
            }
        }
        jumpTo = lineIndexList.length;
    }

    public void Execute(HLCustomFunction ownerFunction) {
        ownerFunction.curLineIndex = jumpTo;
    }
}
